package com.hackerrank.www.datastructures;

import com.hackerrank.www.ReadUtil;


/**
 * Created by 27340 on 2017/5/6.
 */
public class DynamicBetter {
    public static void main(String[] args) {
        int last = 0, x, y;
        int n = ReadUtil.getInt(), q = ReadUtil.getInt(), cmd, c, len;
        int[][] A = new int[n][];
        int[] tmp;
        for(int k = 0; k < q; ++k) {
            cmd = ReadUtil.getInt();
            x = ReadUtil.getInt();
            y = ReadUtil.getInt();
            c = (x^last) % n;
            switch(cmd) {
                case 1:
                    if(A[c] == null)
                        len = 1;
                    else
                        len = A[c].length + 1;
                    tmp = new int[len];
                    if(A[c] != null)
                        System.arraycopy(A[c], 0, tmp, 0, A[c].length);
                    tmp[tmp.length-1] = y;
                    A[c] = tmp;
                    break;
                case 2:
                    System.out.println("x is " + x +" last is " + last + "n is " + n +" c is " + c +" y is " + y );
                    System.out.println(last = A[c][y % A[c].length]);
            }
        }
    }

}
